package itheima04;

import java.io.*;

/*
    将GBK编码的文本文件，转换为UTF-8编码的文本文件
    步骤:
        1.创建InputStreamReader类的对象isr,传递FileInputStream对象,指定编码表GBK
        2.创建OutputStreamWriter类的对象osw,传递FileOutputStream对象,指定编码表UTF-8
        3.循环读(源文件)写(目标文件) 单字符/字符数组
        4.关闭流,释放资源
 */
public class Demo06GBK2UTF8 {
    public static void main(String[] args) throws Exception {
        //1.创建InputStreamReader类的对象isr,传递FileInputStream对象,指定编码表GBK
        InputStreamReader isr = new InputStreamReader(new FileInputStream("day12\\gbk.txt"),"GBK");

        //2.创建OutputStreamWriter类的对象osw,传递FileOutputStream对象,指定编码表UTF-8
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("day12\\utf8.txt"), "UTF-8");

        //3.循环读(源文件)写(目标文件) 单字符/字符数组
        int len = 0;
        char[] chs = new char[1024];
        while((len = isr.read(chs))!=-1) {
            osw.write(chs,0,len);
        }
        //4.关闭流,释放资源
        isr.close();
        osw.close();
    }
}
